Skip to content

fix(evm): fix use-after-free in EXTCODEHASH due to deferred pointer load#368

Merged
zoowii merged 1 commit intoDTVMStack:mainfrom
ys8888john:fix_ret_err
Feb 28, 2026
Merged

fix(evm): fix use-after-free in EXTCODEHASH due to deferred pointer load#368
zoowii merged 1 commit intoDTVMStack:mainfrom
ys8888john:fix_ret_err

Conversation

@ys8888john
Copy link
Contributor

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

2. What is the scope of this PR (e.g. component or file name):

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains CI/CD configuration changes
  • Contains documentation changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

6. Release note

None

Co-authored-by: Aone Copilot <copilot@alibaba-inc.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a JIT use-after-free in the EVM frontend’s EXTCODEHASH handling by changing the runtime interface to return a stable uint256 result buffer (avoiding deferred loads from a pointer into a resizable container).

Changes:

  • Update GetExtCodeHash runtime function type/signature to return const intx::uint256* instead of const uint8_t*.
  • Change evmGetExtCodeHash to convert the host bytes32 to intx::uint256 and return it via storeUint256Result(...) (thread-local buffer).
  • Update MIR builder to call the runtime with the new return type for EXTCODEHASH.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/compiler/evm_frontend/evm_mir_compiler.cpp Switches handleExtCodeHash runtime call to expect a uint256 pointer result.
src/compiler/evm_frontend/evm_imported.h Updates RuntimeFunctions::GetExtCodeHash typedef/signature to U256WithBytes32Fn.
src/compiler/evm_frontend/evm_imported.cpp Implements evmGetExtCodeHash returning a uint256 via the thread-local return buffer instead of a vector-backed bytes pointer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 337 to 352
@@ -347,11 +347,9 @@ const uint8_t *evmGetExtCodeHash(zen::runtime::EVMInstance *Instance,
Instance->chargeGas(zen::evm::ADDITIONAL_COLD_ACCOUNT_ACCESS_COST);
}

auto &Cache = Instance->getMessageCache();
evmc::bytes32 Hash = Module->Host->get_code_hash(Addr);
Cache.ExtcodeHashes.push_back(Hash);

return Cache.ExtcodeHashes.back().bytes;
intx::uint256 HashValue = intx::be::load<intx::uint256>(Hash);
return storeUint256Result(HashValue);
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a regression test that exercises EXTCODEHASH in the JIT path (e.g., multiple EXTCODEHASH results used after subsequent host calls) to ensure the previous deferred-load use-after-free cannot reappear and that the returned hash value is stable/correct across repeated calls.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

@zoowii zoowii merged commit bc16721 into DTVMStack:main Feb 28, 2026
15 checks passed
@ys8888john ys8888john deleted the fix_ret_err branch February 28, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants